package com.pignest.hotel.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;

import com.pignest.hotel.beans.CustomHistory;
import com.pignest.hotel.beans.Living;
import com.pignest.hotel.beans.LivingCustom;
import com.pignest.hotel.dao.CustomHistoryDao;

public class CustomService extends BaseService implements InitializingBean {

	private CustomHistoryDao customHistoryDao;
	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
       // L.setService(this);
	}
	public List<CustomHistory> queryCustomsNoPage( String name,
			 String certificateno,  String certType,  String roomName,
			 String roomTypeId, String phone, String cardNo,String oType, Date sLiveDate,
			 Date eLiveDate){
		return customHistoryDao.queryCustomsNoPage(name, certificateno, certType, roomName, roomTypeId, phone, cardNo,oType, sLiveDate, eLiveDate);
	}
	public List<CustomHistory> queryCustomHisPage( String name, String certificateno, String certType,
             String roomName, String roomTypeId, String phone, String cardNo,String oType,
             Date sLiveDate, Date eLiveDate, int start, int length){
		return customHistoryDao.queryCustomsPage(name, certificateno, certType, roomName, roomTypeId, phone, cardNo, oType, sLiveDate, eLiveDate, start, length);
	}
	public CustomHistory queryCustomHis(String name){
		return customHistoryDao.queryLastLivingCustom(name);
	}
	public void insertCustomWhenCheckOut(Living l){
		List<LivingCustom> cus =customHistoryDao.queryCustoms(l);
		for(LivingCustom c:cus)
		{
			CustomHistory ch = new CustomHistory();
			ch.setName(c.getName());
			ch.setCertificateno(c.getCertificateno());
			ch.setCertificateType(c.getCertificatetype());
			ch.setPrice(l.getAdjustPrice());
			ch.setRoomPrice(l.getRoomPrice());
			ch.setLeaveTime(l.getLeaveDate());
			ch.setLiveTime(l.getLiveTime());
			ch.setMember(l.getMember());
			ch.setRoom(l.getRoom());
			ch.setOpenType(l.getOpenRoomType());
			ch.setPhone(c.getPhone());
			ch.setSex(c.getSex());
			ch.setOpTime(new Date());
            this.insert(ch);
		}
	}
	public CustomHistoryDao getCustomHistoryDao() {
		return customHistoryDao;
	}
	public void setCustomHistoryDao(CustomHistoryDao customHistoryDao) {
		this.customHistoryDao = customHistoryDao;
	}

}
